﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace KBE_HotFix
{
    public class Account : AccountBase
    {
        public AVATAR_INFOS Avatars;
        public override void onAvatarList(AVATAR_INFOS arg1)
        {
            Avatars = arg1;
            if(Avatars.items.Count == 0)
            {
                Event.fireOut("CreateAvatar", null);
            }
            else if(Avatars.items.Count > 1)
            {
                Event.fireOut("SelectAvatar", null);
            }
            else
            {
                Event.fireOut("EnterGame", Avatars.items.First().uuid);
            }
        }

        public override void onCreateAvatar(Byte arg1, AVATAR_INFO_ITEM arg2)
        {
            if(!AckChecker.Check(arg1))
            {
                return;
            }

            if(Avatars == null)
            {
                Avatars = new AVATAR_INFOS();
            }
            Avatars.items.Add(arg2);
            Event.fireOut("EnterGame", Avatars.items.First().uuid);
        }

        public override void onRemoveAvatar(Byte arg1)
        {

        }

        public override void __init__()
        {
            Dbg.DEBUG_MSG("__init__");
            Event.registerIn("reqCreateAvatar", this, "reqCreateAvatar");
            Event.registerIn("reqSelectAvatar", this, "reqSelectAvatar");
            baseEntityCall.reqAvatarList((Byte)Application.platform);
        }

        public override void onEnterWorld()
        {
            Dbg.DEBUG_MSG("----enter world");
        }

        public override void onEnterSpace()
        {
            Dbg.DEBUG_MSG("----enter space");
        }

        public void reqCreateAvatar(string name)
        {
            baseEntityCall.reqCreateAvatar(name, (Byte)Application.platform);
        }

        public void reqSelectAvatar(ulong uuid)
        {
            baseEntityCall.reqSelectAvatar(uuid);
        }
    }
}
